﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using System.Windows.Data;
using System.Globalization;
using System.Windows.Controls.Theming;
using PPFinance.Common;
using PPFinance.Controls;


namespace PPFinance.UI
{
    public partial class MainPage : UserControl
    {


        public MainPage()
        {
            InitializeComponent();



        }



        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            var tab = new Controls.PPTabControl();
            CentextContainer.Child = tab;
            tab.Items.Add(new PPTabItem() { Name = "test1", Header = "test1", CanClosed = false, Content = new UserControl1() });
            var item2 = new PPTabItem() { Name = "test2", Header = "test2", CanClosed = false };
            tab.Items.Add(item2);
            tab.Items.Add(new PPTabItem() { Name = "test3", Header = "test3" });
            slider1.Maximum = 1;
            slider1.Minimum = 0;
            slider1.Value = 1;
            InitTheme();
            var navbar = AssemblyAction.GetObject("PPFinance.UI.NavMenu", "PPFinance.UI.NavMenu.NavMenu", new object[] { }) as UserControl;
            if (navbar != null)
            {
                LeftContainer.Children.Add(navbar);
                MessageBox.Show("loaded Copmlated1");
            }
            var test = AssemblyAction.GetObject("PPFinance.UI.ExpenditureCategory", "PPFinance.UI.ExpenditureCategory.EcPage", new object[] { }) as UserControl;
            if (test != null)
            {
                item2.Content = test;
            }
            //EcPage.xaml
        }

        void InitTheme()
        {
            ThemeList.Items.Add(new ComboBoxItem() { Name = "BubbleCreme", Content = "BubbleCreme", IsEnabled = true });
            ThemeList.Items.Add(new ComboBoxItem() { Name = "BureauBlack", Content = "BureauBlack" });
            ThemeList.Items.Add(new ComboBoxItem() { Name = "BureauBlue", Content = "BureauBlue" });
            ThemeList.Items.Add(new ComboBoxItem() { Name = "ExpressionDark", Content = "ExpressionDark" });
            ThemeList.Items.Add(new ComboBoxItem() { Name = "ExpressionLight", Content = "ExpressionLight" });
            ThemeList.Items.Add(new ComboBoxItem() { Name = "RainierOrange", Content = "RainierOrange" });
            ThemeList.Items.Add(new ComboBoxItem() { Name = "RainierPurple", Content = "RainierPurple" });
            ThemeList.Items.Add(new ComboBoxItem() { Name = "ShinyBlue", Content = "ShinyBlue" });
            ThemeList.Items.Add(new ComboBoxItem() { Name = "ShinyRed", Content = "ShinyRed" });
            ThemeList.Items.Add(new ComboBoxItem() { Name = "System", Content = "System" });


            ThemeList.SelectedItem = (ThemeList.Items.Single(p => (p as ComboBoxItem).Name == ((this.Parent as ContentControl).Parent as ThemeContainer).CurrentTheme) as ComboBoxItem);
            ThemeList.SelectionChanged += ThemeList_SelectionChanged;
        }
        private void ThemeList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SetTheme(ThemeList.SelectedItem as ComboBoxItem);
        }

        //设置相应的theme
        void SetTheme(ComboBoxItem comboBoxItem)
        {
            if (comboBoxItem != null)
            {
                ThemeData cur = null;
                ThemeCollection themems = new ThemeCollection();
                cur = themems[comboBoxItem.Name];
                if (cur != null)
                {
                    ((this.Parent as ContentControl).Parent as ThemeContainer).ChangeTheme(cur);
                    ThemeList.SelectedItem = comboBoxItem;

                }
            }
        }


        void nbMenu_OnClick(string menuText)
        {
            MessageBox.Show(menuText);
        }

        private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            grBodyContainer.Opacity = e.NewValue;

        }

    }

}
